package com.wqh.data.collection.service;

import com.wqh.common.constants.RedisConstant;
import com.wqh.data.collection.dao.WeatherCollectionDao;
import com.wqh.sevice.city.CityDataService;
import com.wqh.sevice.pojo.City;
import com.wqh.sevice.pojo.WeatherResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author wanqh
 * @date 2018/02/23 15:56
 * @description:
 */
@Slf4j
@Component
public class WeatherDataSync {

    @Autowired
    private CityDataService cityDataService;

    @Autowired
    private WeatherCollectionDao weatherCollectionDao;

    @Scheduled(fixedDelay = 1000*60*60,initialDelay = 5000)
    public void syncDateByCityId() throws Exception {
        List<City> cities = cityDataService.listCity();
        for (City city : cities){
            log.info("Weather Data Sync Job, cityName{};cityId{}",city.getCityName(),city.getCityId());
            weatherCollectionDao.dataCollection(city.getCityId());
        }
    }
}
